package cn.itsource.basic.util;

import cn.itsource.basic.constant.PetHomeConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="响应对象",description = "不管成功还是失败，json交互对象")
public class AjaxResult {

    @ApiModelProperty(value = "状态码,0000就是成功，其它都是失败")
    private String code = PetHomeConstant.SUCCESS_CODE;    // 状态码
    @ApiModelProperty(value = "提示信息")
    private String message = "OK";   // 返回消息
    @ApiModelProperty(value = "成功或者失败 true成功，false：失败")
    private Boolean success = true;        // 返回转态
    @ApiModelProperty(value = "携带的数据")
    private Object data;        // 返回数据

    /**
     * 返回操作成功的消息
     * @return
     */
    public static AjaxResult createSuccess(){
        return new AjaxResult();
    }
    
    /**
     * 返回操作成功的消息
     * @param obj
     * @return
     */
    public static AjaxResult createSuccess(Object obj){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(obj);
        return ajaxResult;
    }

    /**
     * 返回操作失败的消息
     * @param message
     * @return
     */
    public static AjaxResult createError(String message){
        return createError(PetHomeConstant.ERROR_CODE, message);
    }

    /**
     * 返回操作失败的消息
     * @param code
     * @param message
     * @return
     */
    public static AjaxResult createError(String code,String message){
        return new AjaxResult(code,message,false,null);
    }
}